package clientUtilGUI;

import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import clientMain.Main;
import clientView.Dep_Condition;
import clientView.Dep_List;

public class Tab_Department extends JToolBar implements ActionListener {
	private JButton btnDepInfo;
	private JButton btnDepList;

	public Tab_Department(){
		setFloatable(false);
		setOrientation(JToolBar.HORIZONTAL);
		setMargin(new Insets(0, 6, 0, 2));
		
		btnDepInfo = new JButton(UtilityGUI.subMenuDepInfo, new ImageIcon("src/image/conference-icon.png"));
		btnDepInfo.setVerticalTextPosition(JButton.BOTTOM);
		btnDepInfo.setHorizontalTextPosition(JButton.CENTER);
		btnDepInfo.addActionListener(this);
		add(btnDepInfo);
		
		btnDepList = new JButton(UtilityGUI.subMenuDepList, new ImageIcon("src/image/accept_page.png"));
		btnDepList.setVerticalTextPosition(JButton.BOTTOM);
		btnDepList.setHorizontalTextPosition(JButton.CENTER);
		btnDepList.addActionListener(this);
		add(btnDepList);		
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()== btnDepInfo){
			new Dep_Condition(Main.main).setVisible(true);
		}
		
		if(e.getSource() == btnDepList){
			int index = Main.jTabbedPane.positionTab(UtilityGUI.tabDepList);
			if(index == -1){
				Main.jTabbedPane.addTab(new Dep_List(), UtilityGUI.tabDepList);
				Main.jTabbedPane.setSelectedIndex(Main.jTabbedPane.getTabCount()-1);
			}else{
				Main.jTabbedPane.setSelectedIndex(index);
				return;
			}
		}
	}
}
